Skip to content

Adding value_of_css_property method#291

Merged
mshriver merged 1 commit intoRedHatQE:mainfrom
digitronik:value_of_css_property
Oct 22, 2025
Merged

Adding value_of_css_property method#291
mshriver merged 1 commit intoRedHatQE:mainfrom
digitronik:value_of_css_property

Conversation

@digitronik
Copy link
Member

@digitronik digitronik commented Oct 22, 2025

Summary by Sourcery

Add a new method to retrieve computed CSS property values of elements, validate it with tests, and update test viewport dimensions

New Features:

  • Introduce value_of_css_property method to fetch computed CSS property values

Enhancements:

  • Update default test viewport size to 1920x1080

Tests:

  • Add tests for value_of_css_property using margin and border-color properties

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 22, 2025

Reviewer's Guide

Introduces a new value_of_css_property method to fetch computed CSS properties from elements, adds corresponding tests, and updates the default viewport size in test fixtures.

Sequence diagram for value_of_css_property method execution

sequenceDiagram
  actor User
  participant Browser
  participant Element
  User->>Browser: value_of_css_property(locator, property)
  Browser->>Browser: logger.debug(...)
  Browser->>Element: element(locator)
  Browser->>Element: evaluate("window.getComputedStyle(element).getPropertyValue(property)")
  Element-->>Browser: CSS property value
  Browser-->>User: CSS property value
Loading

Class diagram for the new value_of_css_property method in Browser

classDiagram
class Browser {
  +set_attribute(attr: str, value: str, *args, **kwargs)
  +value_of_css_property(locator: LocatorAlias, property: str, *args, **kwargs) Optional[str]
  +size_of(*args, **kwargs) Size
}
Browser : value_of_css_property() uses element()
Browser : value_of_css_property() calls logger.debug()
Browser : value_of_css_property() returns el.evaluate()
Loading

File-Level Changes

Change Details Files
Add value_of_css_property method
  • Define value_of_css_property with locator, property, args, kwargs
  • Log retrieval attempt
  • Locate element and evaluate JS to get computed style property
src/widgetastic/browser.py
Add tests for value_of_css_property
  • Test margin property returns '5px'
  • Test border-color property returns correct RGB value
testing/test_browser.py
Update default viewport resolution
  • Change viewport width from 1280 to 1920
  • Change viewport height from 720 to 1080
testing/conftest.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/widgetastic/browser.py:807` </location>
<code_context>
+        Returns:
+            Value of css property.
+        """
+        self.logger.debug("Retrieving value of css property: %r ", locator)
+        el = self.element(locator=locator)
+        return el.evaluate(
</code_context>

<issue_to_address>
**suggestion:** The debug log message could include the property name for better traceability.

Adding the property name to the log will clarify which property is being accessed for each locator, improving debugging of style-related issues.

```suggestion
        self.logger.debug("Retrieving value of css property '%s' for locator: %r", property, locator)
```
</issue_to_address>

### Comment 2
<location> `testing/test_browser.py:536-541` </location>
<code_context>
     assert browser.get_attribute("foo", "#invisible") == "bar"


+def test_value_of_css_property(browser):
+    assert browser.value_of_css_property(locator="#test-image-full", property="margin") == "5px"
+    assert (
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for edge cases such as non-existent elements and invalid CSS properties.

Please include tests for scenarios where the locator does not match any element and where the CSS property is invalid or unset, to verify correct error handling or return values.

```suggestion
def test_value_of_css_property(browser):
    assert browser.value_of_css_property(locator="#test-image-full", property="margin") == "5px"
    assert (
        browser.value_of_css_property(locator="#test-image-full", property="border-color")
        == "rgb(221, 221, 221)"
    )

def test_value_of_css_property_nonexistent_element(browser):
    # Should raise an exception or return None/empty string if element does not exist
    try:
        result = browser.value_of_css_property(locator="#does-not-exist", property="margin")
        # Accept either None or empty string as valid "not found" result
        assert result in (None, "")
    except Exception:
        # If an exception is expected, pass the test
        pass

def test_value_of_css_property_invalid_property(browser):
    # Should raise an exception or return None/empty string if property is invalid or unset
    result = browser.value_of_css_property(locator="#test-image-full", property="not-a-real-property")
    assert result in (None, "")
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.50%. Comparing base (6d6b124) to head (e5966fa).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #291   +/-   ##
=======================================
  Coverage   93.49%   93.50%           
=======================================
  Files          19       19           
  Lines        2613     2617    +4     
=======================================
+ Hits         2443     2447    +4     
  Misses        170      170           
Flag Coverage Δ
unittests 93.50% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@digitronik digitronik force-pushed the value_of_css_property branch 2 times, most recently from 67f3ea5 to 9fd3e18 Compare October 22, 2025 08:29
@digitronik digitronik force-pushed the value_of_css_property branch from 9fd3e18 to e5966fa Compare October 22, 2025 08:36
@mshriver mshriver merged commit 4167850 into RedHatQE:main Oct 22, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants